//
//  WNHomeTableViewCell.swift
//  XLWeibo
//
//  Created by 风不会停息 on 2017/7/27.
//  Copyright © 2017年 风不会停息. All rights reserved.
//

import UIKit
import SnapKit

class WNHomeTableViewCell: UITableViewCell {
    
    var toolbarTopConstranit : Constraint?
    
    var statusViewModel : WNStatusViewModel?{
        didSet{
            originalView.statusViewModel = statusViewModel
            
            toolbarTopConstranit?.deactivate()
            if statusViewModel?.status?.retweeted_status != nil {
                
                retweetView.isHidden = false
                
                toolBar.snp.makeConstraints({ (make) in
                    toolbarTopConstranit = make.top.equalTo(retweetView.snp.bottom).constraint
                })
                
                retweetView.statusViewModel = statusViewModel
            }
            else{
                retweetView.isHidden = true
                
                toolBar.snp.makeConstraints({ (make) in
                    
                    toolbarTopConstranit = make.top.equalTo(originalView.snp.bottom).constraint
                })
            }
            
            toolBar.statusViewModels = statusViewModel
            
        }
    }
    
    // MARK:----懒加载控件
    fileprivate lazy var originalView : WNHomeOriginalView = WNHomeOriginalView()
    //  转发微博视图
    fileprivate lazy var retweetView: WNHomeReweetView  = WNHomeReweetView()
    //  微博toolbar
    fileprivate lazy var toolBar: WNHoomToolBar = WNHoomToolBar()


    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupUI(){
        
        backgroundColor = UIColor.white
        contentView.addSubview(originalView)
        contentView.addSubview(toolBar)
        contentView.addSubview(retweetView)
        
        originalView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(8)
            make.leading.trailing.equalToSuperview()
            
        }
        retweetView.snp.makeConstraints { (make) in
            make.top.equalTo(originalView.snp.bottom)
            make.leading.trailing.equalTo(originalView)
        }
        
        toolBar.snp.makeConstraints { (make) in
            //  oc里面直接接收结果就可以了，因为约束成功后返回的就是约束对象
            toolbarTopConstranit = make.top.equalTo(retweetView.snp.bottom).constraint
            make.leading.trailing.equalTo(retweetView)
            make.height.equalTo(35)
            
            //  关键约束,确定行高
            make.bottom.equalTo(contentView)
            
        }

        
    }
    
    
    

}
